<!--  -->
<template>
  <div class="ranking">
    <div class="header">
      <van-icon name="arrow-left" size="18" @click="goBack()" />
      <p>排行榜</p>
      <span></span>
    </div>
    <div class="content">
      <van-search
        v-model="search"
        placeholder="请输入需要查询的经纪人"
        @input="onSearch"
        right-icon="search"
        left-icon=""
      />
      <div class="search">
        <div>
          <img
            src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.zcool.cn%2Fcommunity%2F01b82557b5595d0000018c1bbf3f58.jpg%40900w_1l_2o_100sh.jpg&refer=http%3A%2F%2Fimg.zcool.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1634890966&t=3379b248c65dc5241d060794a1c5aacb"
            alt=""
          />
          <p>李群</p>
        </div>
        <div>
          <img
            src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fup.enterdesk.com%2Fedpic%2Fd2%2Fab%2Fd1%2Fd2abd1ef76df02dd19534946f0ebbd59.jpg&refer=http%3A%2F%2Fup.enterdesk.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1634890774&t=8fbf339d1b1a05159455592ed1448af1"
            alt=""
          />
          <p>殷晗</p>
        </div>
        <div>
          <img
            src="https://inews.gtimg.com/newsapp_bt/0/13960520356/1000"
            alt=""
          />
          <p>陈东红</p>
        </div>
      </div>
      <dl
        v-for="(item, idx) in list"
        :key="idx"
        class="list"
        @click="goDetail(item)"
      >
        <p>0{{ item.id }}</p>
        <dt>
          <img :src="item.img" alt="" />
        </dt>
        <dd>
          <span>
            <p>{{ item.name }}</p>
            <p>{{ item.info }}</p>
          </span>
          <span>
            <van-icon name="chat-o" @click="goConsult()" />
            <van-icon name="phone-o" @click="goPhone()" />
          </span>
        </dd>
      </dl>
    </div>
  </div>
</template>

<script>
import { getBroker } from "@/api";
import debounce from "../../utils/debounce";
export default {
  // 组件状态值
  data() {
    return {
      search: "",
      list: [],
    };
  },
  // 计算属性
  computed: {},
  // 组件方法
  methods: {
    //获取数据
    async getList() {
      const res = await getBroker({ value: this.search });
      console.log(res);
      this.list = res.data.data;
    },
    //返回上一级
    goBack() {
      this.$router.push("/");
    },
    //搜索
    onSearch() {
      debounce(() => {
        this.getList();
      }, 500);
    },
    //跳详情
    goDetail(item) {
      this.$router.push(`/rankDetail/${item.id}`);
    },
    //跳转咨询页面
    goConsult() {
      this.$router.push("/consult");
    },
    //跳转到电话咨询页面
    goPhone() {
      this.$router.push("/phone");
    },
  },
  /**
   * 组件实例创建完成，属性已绑定，但DOM还未生成，$ el属性还不存在
   */
  created() {
    this.getList();
  },
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<!--使用了scoped属性之后，父组件的style样式将不会渗透到子组件中，-->
<!--然而子组件的根节点元素会同时被设置了scoped的父css样式和设置了scoped的子css样式影响，-->
<!--这么设计的目的是父组件可以对子组件根元素进行布局。-->
<style lang="scss" scoped>
.ranking {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
}
.header {
  width: 100%;
  height: 70px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 18px;
  color: #fff;
  background: #4381e6;
  padding: 0 15px;
}
.content {
  flex: 1;
  overflow: auto;
}
.search {
  width: 100%;
  padding: 0 10px;
  background-image: url("../../assets/2.webp");
  display: flex;
  justify-content: space-around;
  div {
    width: 32%;
    background: #fff;
    margin-top: 50px;
    text-align: center;
    padding-top: 10px;
    border-radius: 15px 15px 0 0;
    img {
      width: 60px;
      border-radius: 50%;
    }
  }
  div:nth-child(2) {
    margin-top: 60px;
    padding-top: 20px;
    height: 130px;
    background: #fff;
    img {
      width: 70px;
      border-radius: 50%;
    }
  }
  div:nth-child(1) {
    height: 110px;
    margin-top: 80px;
    background: #fff;
  }
  div:nth-child(3) {
    height: 110px;
    margin-top: 80px;
    background: #fff;
  }
}
.list {
  width: 100%;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #ccc;
  padding: 5px 20px;
  img {
    width: 70px;
    border-radius: 50%;
  }
  dd {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    span:nth-child(1) {
      line-height: 30px;
      p:nth-child(2) {
        color: #999;
      }
    }
    span:nth-child(2) {
      .van-icon {
        width: 30px;
        height: 30px;
        text-align: center;
        line-height: 30px;
        border-radius: 50%;
        font-weight: bold;
        color: red;
        background: rgba(255, 0, 0, 0.2);
        margin-right: 10px;
      }
    }
  }
}
</style>
